﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Text;

namespace WsusWebAdmin.Web.Helpers
{
    public static class AjaxHelperExtensions
    {
        public static string RenderPartial(this AjaxHelper helper, string divId, string controllerName, string actionName, object routeValues)
        {
            RouteValueDictionary routeValuesDictionary = new RouteValueDictionary(routeValues);
            var url = UrlHelper.GenerateUrl(null, actionName, controllerName, routeValuesDictionary, helper.RouteCollection, helper.ViewContext.RequestContext, true);
            

            StringBuilder sb = new StringBuilder();
         

            sb.AppendLine(string.Format("<div id=\"{0}\">", divId))
              .AppendLine("aaa")
              .AppendLine("</div>")
              .AppendLine("<script type=\"text/javascipt\">")
              .AppendFormat(@"$(document).ready(function(){{
                                                        $('#{0}').load('{1}');
                                                }});", divId, url).AppendLine()
              .AppendLine("</script>");
             
            
            return sb.ToString();
        }
    }
}